package com.crm;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.net.InetAddress;
import java.util.Objects;

@SpringBootApplication
@Slf4j
@EnableScheduling
public class CRMApplication {

	public static void main(String[] args) throws Exception {
		ConfigurableApplicationContext application = SpringApplication.run(CRMApplication.class, args);
		Environment env = application.getEnvironment();
		String ip = InetAddress.getLocalHost().getHostAddress();
		String port = env.getProperty("local.server.port");
		String path = Objects.toString(env.getProperty("server.servlet.context-path"), "").trim();

		String localUrl = String.format("http://localhost:%s%s/", port, path);
		String externalUrl = String.format("http://%s:%s%s/", ip, port, path);
		String swaggerUrl = String.format("http://%s:%s%s/swagger-ui/index.html#/", ip, port, path);

		log.info(String.format("""
        ----------------------------------------------------------
        \tApplication store-backend is running! Access URLs:
        \t本地访问: \t%s
        \t外网访问: \t%s
        \t接口文档: \t%s
        ----------------------------------------------------------""",
				localUrl, externalUrl, swaggerUrl));
	}

}
